<template>
    <!-- 头部 -->
    <templateHead></templateHead>
    <!-- 菜单 -->
    <templateMenu></templateMenu>
    <!-- 内容 -->
    <div v-for="(item,index) in templateData" :key="index">
        <!--广告组件-->
        <div v-if="item.sectorName=='adSector'">
            <templateAd :skinId="skinId" :adData="adData" :adTag="item.ad.ad_tag"></templateAd>
        </div>
        <!--资讯正文-->
        <div v-if="item.sectorName=='articleSector'">
            <templateArticle :skinId="skinId" :templateData="item.componentList" :articleData="articleData" :routeId="routeId"></templateArticle>
        </div>
    </div>
    <!-- 底部 -->
    <templateFoot></templateFoot>
</template>

<script setup lang="ts">
import type { IArticleDetail,ISurveyResult,ISurveyResultData } from '@/utils/dataInterface';
//0.加载全局模板组件 start---------------------------------------->
//0.1全局通栏
import templateHead from '@/components/template/sector/head/1200x200/1.vue'
import templateMenu from '@/components/template/sector/menu/1200x130/1.vue'
import templateFoot from '@/components/template/sector/foot/1200x580/1.vue'
//0.2局部通栏
//0.2.1广告组件
import templateAd from '@/components/template/sector/body/ad/1200x90/1.vue'
//0.2.2资讯正文通栏
import templateArticle from '@/components/template/sector/body/article/article/1200x1710/1.vue'
//0.加载全局模板组件 end---------------------------------------->

//1.获得基本信息单元 start---------------------------------------->
//1.1获得页面依赖
import { ref, onMounted } from 'vue';
//1.2使用url查询导航池id
const targetSegment = getRoutePath(1);//当前页面的url路径 这是第一层 所以获得域名后面的第一层url
const routeId = ref<number>(0);//当前url路径代表的cid
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
if (getRouteId.code == 200) {
    routeId.value = getRouteId.data.category_id
}
//1.3获得pinia源
import { useTemplateBaseStore } from '@/stores/templateBase'
const templateBaseStore:any = useTemplateBaseStore()
//1.4获得该页的皮肤id - 在每个组件中也是同样的获得方法
const skinId = ref<number>(0)
const websiteId = ref<number>(0)
//1.5获得站点基本信息
const responseStatus:any = await requestDataPromise('/web/getWebsiteAllinfo', {
    method: 'GET',
    query: {
        'link_textnum':24,
        'link_imgnum':18,
        'link_footnum':4
    },
});
if (responseStatus.code == 200) {
    //1.6.1设置站点基本信息
    templateBaseStore.setWebSiteInfo(responseStatus.data)
    websiteId.value = responseStatus.data.website_head.id;
    //1.6.2设置皮肤id
    skinId.value = templateBaseStore.webSiteInfo.website_foot.foot_info.template_id;
}
//1.获得基本信息单元 end---------------------------------------->

//2.页面数据 start---------------------------------------->
//2.1获得页面数据
const response:any = await requestDataPromise('/client/indexData', {
    method: 'POST',
    body: {
        'website_id':websiteId.value,
        'getpage':'article'
    },
});
//2.2模板数据
const templateData = response.data.template.article;
console.log(templateData)
//2.3广告数据
const adData = ref<any[]>([]);
adData.value.push(response.data.ad.top)
for(let item of response.data.ad.article){
    adData.value.push(item)
}
templateBaseStore.setAdList(adData.value)
//2.4获得文章详情
const route:any = useRoute();
const articleId = parseInt(route.params.id); //获得该页面的id
const articleData = ref<IArticleDetail>({
    title:'',
    introduce:'',
    keyword:'',
    author:'',
    copyfrom:'',
    content:'',
    website_name:'',
    updated_at:'',
    suffix:''
});
const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
    method: 'GET',
    query: {
        'articleid': articleId
    },
});
if (mkdata.code == 200) {
    //设置文章正文
    articleData.value = mkdata.data;
    //设置seo
    let seoTitle = mkdata.data.title;
    let seoDescription = mkdata.data.introduce;
    let seoKeywords = mkdata.data.keyword;
    let seoSuffix = mkdata.data.suffix;
    let seoName = mkdata.data.website_name;
    useHead({
        title: seoTitle + "_" + seoName + "_" + seoSuffix,
        meta: [
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
        ]
    });
}
//2.页面数据 end---------------------------------------->
</script>

<style lang="less" scoped>
@import url('@/assets/css/detail.less');
</style>